import React from 'react';
import {UserLogin} from "../http/Request";
import {Toast} from 'antd-mobile';

require('../assets/css/Login.css');


//home.js
export default class Login extends React.Component {

    state = {
        userInfo: {
            //     "body": {
            //         "mobile": "18510200754",
            //         "password": "123456"
            //     }
        },
        mobile: '18510200754',
        password: '123456'
    };


    toHome = (props) => {
        this.props.history.push({pathname: "/Home"})
    };

    showToast() {
        Toast.info('登陆成功', 1);
    };

    handleSubmit() {
        let body = {};
        body['mobile'] = this.state.mobile;
        body['password'] = this.state.password;
        // eslint-disable-next-line react/no-direct-mutation-state
        UserLogin(body).then(
                (res) => {
                    console.log(res);
                    this.showToast();
                    this.cookie.setCookie('token', res.body.token);
                    this.toHome();

                },
                (error) => {
                    console.log("get response failed!", error);
                }
        );

    };


    render() {
        return (
                <div className={'loginBox'}>
                    <div className={'loginTop'}>
                        <img className={'loginImg'} src="../assets/image/logo.png" alt=""/>
                    </div>
                    <div className={'loginFrom'}>
                        <input
                                type="phone"
                                value={this.state.mobile}
                                onChange={e => this.setState({mobile: e.target.value})}
                                placeholder={'请输入账号'}
                        />

                        <input
                                type="password"
                                value={this.state.password}
                                onChange={e => this.setState({password: e.target.value})}
                                placeholder={'请输入密码'}
                        />

                        <button onClick={this.handleSubmit.bind(this)}>登录</button>
                    </div>
                </div>
        )
    }
}


// eslint-disable-next-line no-unused-vars
const styleObj = {};
